package com.csxy.lsh.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csxy.lsh.R;
import com.csxy.lsh.entity.EduCourse;
import com.csxy.lsh.entity.vo.ChapterVo;
import com.csxy.lsh.entity.vo.CourseFrontVo;
import com.csxy.lsh.entity.vo.CourseWebVo;
import com.csxy.lsh.service.EduChapterService;
import com.csxy.lsh.service.EduCourseService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/coursefront")
public class CourseFrontController {
    @Autowired
    private EduCourseService educourseService;
    @Autowired
    private EduChapterService eduChapterService;



    @PostMapping("getFrontCourseList/{page}/{limit}")
    public R getFrontCourseList(@PathVariable long page, @PathVariable long limit,
                                @RequestBody(required = false) CourseFrontVo courseFrontVo){
        Page<EduCourse> pageCourse = new Page<>(page,limit);
        Map<String,Object> map = educourseService.getCourseFrontInfo(pageCourse,courseFrontVo);

        return R.ok().data(map);
    }

    //课程详情的方法
    @GetMapping("getFrontCourseInfo/{courseId}")
    public R getFrontCourseInfo(@PathVariable String courseId, HttpServletRequest  request){

        CourseWebVo courseWebVo= educourseService.getBaseCourseInfo(courseId);

        List<ChapterVo> chapterVoList= eduChapterService.getChaterVideoByCourseId(courseId);

        return R.ok().data("courseWebVo",courseWebVo).data("chapterVideoList",chapterVoList);
    }

}
